package models;

import java.util.*;

import javax.persistence.*;

import play.db.ebean.*;
import play.db.ebean.Model.Finder;
import play.data.format.*;
import play.data.validation.*;
import com.avaje.ebean.*;

@Entity
public class QcmNiveauQuestion extends Model {

	@Id
	private Long idQcmNiveauQuestion;

	@ManyToOne
	private Qcm qcm;

	@ManyToOne(cascade=CascadeType.ALL)
	private NiveauQuestion niveauQuestion;

	@Constraints.Required
	private double pointPositif;

	@Constraints.Required
	private double pointNegatif;
	
	public static Finder<Long, QcmNiveauQuestion> find = new Finder<Long, QcmNiveauQuestion>(Long.class,
			QcmNiveauQuestion.class);
	/**
	 * La méthode permet de retrouver une question à partir de son ID
	 * 
	 * @param id
	 * @return Qcm
	 */
	public static QcmNiveauQuestion findById(Long id) {
		return Ebean.find(QcmNiveauQuestion.class, id);
	}
	
	public static List<QcmNiveauQuestion> findByStatut(Statut statut){
		return find.where().eq("statut", statut.name()).findList(); 
	}

	public static List<QcmNiveauQuestion> findAll() {
		return find.all();
	}

	public static void create(QcmNiveauQuestion qcmNivQuest) {
		qcmNivQuest.save();
	}

	public static void update(QcmNiveauQuestion qcmNivQuest) {
		qcmNivQuest.update();
	}

	/*
	 * GETTER ET SETTER
	 */
	public Long getIdQcmNiveauQuestion() {
		return idQcmNiveauQuestion;
	}

	public void setIdQcmNiveauQuestion(Long idQcmNiveauQuestion) {
		this.idQcmNiveauQuestion = idQcmNiveauQuestion;
	}

	public Qcm getQcm() {
		return qcm;
	}

	public void setQcm(Qcm qcm) {
		this.qcm = qcm;
	}

	public NiveauQuestion getNiveauQuestion() {
		return niveauQuestion;
	}

	public void setNiveauQuestion(NiveauQuestion niveauQuestion) {
		this.niveauQuestion = niveauQuestion;
	}

	public double getPointPositif() {
		return pointPositif;
	}

	public void setPointPositif(double pointPositif) {
		this.pointPositif = pointPositif;
	}

	public double getPointNegatif() {
		return pointNegatif;
	}

	public void setPointNegatif(double pointNegatif) {
		this.pointNegatif = pointNegatif;
	}

}
